Ext.define('App.controller.carDealer.CarDealerViewController', {
	extend : 'Ext.app.ViewController',
	alias : 'controller.carDealerViewController',
	menu : Ext.widget('menu'),
	control : {
        'carDealerView carDealerSearch basesearchform' : {
            beforerender : function(form) {
                var buttons = {
                    'bs/carDealer/saveCarDealer' : function(permit) {
                        var name = form.down("[name=name]").getValue();
                        if(!name){
                            BaseUtil.toast("请填写车系");
                            return;
                        }
                        BaseUtil.post(permit.url,function(data){
                            BaseUtil.toast(data.msg);
                            Ext.StoreMgr.get('carDealer.CarDealerStore').reload();
                        },form.getValues());
                    },
                    'bs/carDealer/updateCarDealer' : function(permit) {
                        var name = form.down("[name=name]").getValue();
                        if(!name){
                            BaseUtil.toast("请填写车型系");
                            return;
                        }
                        BaseUtil.post(permit.url,function(data){
                            BaseUtil.toast(data.msg);
                            Ext.StoreMgr.get('carDealer.CarDealerStore').reload();
                        },form.getValues());
                    }

                };
                BaseUtil.createPermitBar(form, buttons);
            },
            render : function() {
                BaseUtil.loadStore(Ext.StoreMgr.get('carDealer.CarDealerStore'),Ext.getCmp('carDealerView').down('carDealerSearch form').getForm().getFieldValues());
            }
        },
		'carDealerView carDealerList' : {
            itemclick:function(view, record, item, index, e, eOpts){
                var search  =  Ext.getCmp('carDealerView').down('carDealerSearch form');
                search.reset();
                search.loadRecord(record);
            },
		},
		'carDealerView carDealerSearch [action=search] ' : {
			click : function() {
				BaseUtil.loadStore(Ext.StoreMgr.get('carDealer.CarDealerStore'),Ext.getCmp('carDealerView').down('carDealerSearch form').getForm().getFieldValues());
			}
		}
	}
});